package com.metaera.app.ui.activities;

import android.graphics.Color;
import android.graphics.drawable.Drawable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.controller.core.IPaginationPresenter;
import com.metaera.app.controller.core.SimplePaginationPresenter;
import com.metaera.app.controller.view.core.IPaginationView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.model.BasicListResponse;
import com.metaera.app.data.model.MorningPostResponse;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.ui.adapters.MorningPostAdapter;
import com.metaera.app.ui.core.BaseRequestListActivity;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.Observable;

/**
 * 金色早八点
 */
public class MorningPostActivity extends BaseRequestListActivity<MorningPostResponse> {

    @Override
    protected String getActivityTitle() {
        return getString(R.string.home_morning_post);
    }

    @Override
    protected BaseQuickAdapter<MorningPostResponse, BaseViewHolder> createAdapter(RecyclerView recyclerView) {
        recyclerView.setBackgroundColor(Color.WHITE);
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
        Drawable drawable = ContextCompat.getDrawable(recyclerView.getContext(), R.drawable.shape_item_divider);
        dividerItemDecoration.setDrawable(drawable);
        recyclerView.addItemDecoration(dividerItemDecoration);
        return new MorningPostAdapter();
    }

    @Override
    protected IPaginationPresenter<IPaginationView<MorningPostResponse>, MorningPostResponse> createPresenter() {
        return new SimplePaginationPresenter<MorningPostResponse>() {
            @Override
            protected Observable<BasicListResponse<MorningPostResponse>> execute() {
                return DataRepository.getInstance().getNewsDetails(mPage, ApiParam.PAGE_SIZE);
            }
        };
    }

}
